{% extends "manager.html" %}
{% block body %}
<div class="panel panel-info w60">
  <div class="panel-heading">多说留言板</div>
  <div class="panel-body">
	<table>
	<tr>
	<td>
	  <a href="http://dev.duoshuo.com/docs" target="_blank">不知道什麼是多說?</a>
	  <a href="http://duoshuo.com/" target="_blank">点此申请？</a>
	  多說ID：<input type="text" id="DS" value="{{ DUOSHUO }}"><button id="DUOSHUO" class="btn btn-primary">保存</button></td>
	</tr>
	</table>
  </div>
</div>
<div class="panel panel-primary w60">
  <div class="panel-heading">导航链接</div>
  <div class="panel-body">
    <div class="table-responsive w90">
	<table id="main" class="table table-striped table-bordered table-hover">
	<thead>
	<tr>
	<td>ID</td>
	<td>名称</td>
	<td>链接</td>
	<td>管理</td>
	</tr>
	</thread>
	<tbody>
	{% if not NAV %}
	<tr><td><a href="#" onclick="edit('','','NAV','')" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span>新建</a></td></tr>
	{% else %}
	{% for i in NAV %}
	<tr>
	<td>{{ i[0] }}</td>
	<td>{{ i[1] }}</td>
	<td>{{ i[2] }}</td>
	<td>
	<button onclick="del({{i[0]}},'{{i[1]}}','NAV')" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span>刪除</button>
	<a href="#" onclick="edit('','','NAV','')" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span>新建</a>
	<a href="#" onclick="edit({{i[0]}},'{{i[1]}}','NAV','{{i[2]}}')" class="btn btn-primary"><span class="glyphicon glyphicon-edit"></span>编辑</button>
	</td>
	</tr>
	{% end %}
	{% end %}
	</tbody>
	</table>
  </div>
  </div>
</div>
<div class="panel panel-success w60">
  <div class="panel-heading">文章底部</div>
  <div class="panel-body">
    <div class="table-responsive w90">
	<table id="main" class="table table-striped table-bordered table-hover">
	<thead>
	<tr>
	<td>ID</td>
	<td>名称</td>
	<td>备注</td>
	<td>管理</td>
	</tr>
	</thread>
	<tbody>
	{% if not LAST %}
	<tr><td><a href="#" onclick="edit('','','LAST','')" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span>新建</a></td></tr>
	{% else %}
	{% for i in LAST %}
	<tr>
	<td>{{ i[0] }}</td>
	<td>{{ i[1] }}</td>
	<td>{{ i[2] }}</td>
	<td>
	<button onclick="del({{i[0]}},'{{i[1]}}','LAST')" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span>刪除</button>
	<a href="#" onclick="edit('','','LAST','')" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span>新建</a>
	<a href="#" onclick="edit({{i[0]}},'{{i[1]}}','LAST','{{ i[2] }}')" class="btn btn-primary"><span class="glyphicon glyphicon-edit"></span>编辑</button>
	</td>
	</tr>
	{% end %}
	{% end %}
	</tbody>
	</table>
  </div>
  </div>
</div>
<div class="panel panel-info w60">
  <div class="panel-heading">友情链接</div>
  <div class="panel-body">
    <div class="table-responsive w90">
	<table id="main" class="table table-striped table-bordered table-hover">
	<thead>
	<tr>
	<td>ID</td>
	<td>名称</td>
	<td>链接</td>
	<td>管理</td>
	</tr>
	</thread>
	<tbody>
	{% if not LINK %}
	<tr><td><a href="#" onclick="edit('','','LINK','')" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span>新建</a></td></tr>
	{% else %}
	{% for i in LINK %}
	<tr>
	<td>{{ i[0] }}</td>
	<td>{{ i[1] }}</td>
	<td>{{ i[2] }}</td>
	<td>
	<button onclick="del({{i[0]}},'{{i[1]}}','LINK')" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span>刪除</button>
	<a href="#" onclick="edit('','','LINK','')" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span>新建</a>
	<a href="#" onclick="edit({{i[0]}},'{{i[1]}}','LINK','{{ i[2] }}')" class="btn btn-primary"><span class="glyphicon glyphicon-edit"></span>编辑</button>
	</td>
	</tr>
	{% end %}
	{% end %}
	</tbody>
	</table>
  </div>
  </div>
</div>
<div class="panel panel-info w60">
  <div class="panel-heading">统计代码</div>
  <div class="panel-body">
	<textarea class="form-control" id="JS" name="JS" rows="15"></textarea>
	<button type="button" id="jsupdate" class="btn btn-primary">提交</button>
  </div>
</div>
<!-- Update-->
<div class="modal fade" id="Cedit" tabindex="-1" role="dialog" aria-labelledby="NewModal" aria-hidden="true">
  <div class="modal-dialog w35">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="add"><b>设定：</b></h4>
      </div>
	  <form class="form-signin" method="post">
      <div class="modal-body">
        <div class="form-group">
		<table class="w90" id='tedit'>
		</table>
	    </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="submit" id="userupdate" class="btn btn-primary">提交</button>
		</form>
      </div>
    </div>
  </div>
</div>
{% end %}
{% block js %}
<script>
var xsrf=$.cookie("_xsrf")
$(function(){
	$.post("/custom",{CMD:'JS',TYPE:'CX',_xsrf:xsrf},function(data){$("#JS").val(data)});
})
function del(id,name,type){
var msg="確定要刪除" +name+"嗎？\n注意：刪除后將無法恢復！"
	if (confirm(msg)){
	$.post('/custom',{CMD:'DEL',ID:id,TYPE:type,_xsrf:xsrf},function(data){location.reload();})
	};
}

function edit(id,name,type,vals){
	var html = "<input type=\"hidden\" name=\"TYPE\" value=\""  + type + "\"><input type=\"hidden\" name=\"_xsrf\" value=\"" + xsrf + 
	"\"><input type=\"hidden\" id=\"CMD\" name=\"CMD\" value=\"\" ><input type=\"hidden\" id=\"ID\" name=\"ID\" value=\"\" ><tr><td>Name:</td><td><input type=\"text\" class=\"form-control\" id=\"name\" name=\"name\" value=\"" + name + "\"></td></tr>" 
	if (type=='LAST'){
		html = html + "<tr><td>Remark:</td><td><input type=\"text\" class=\"form-control\" id=\"remark\" name=\"remark\" value=\"" + vals + "\"></td></tr>" +
				"<tr><td>HTML:</td><td><textarea class=\"form-control\" id=\"EHTML\" name=\"EHTML\" rows=\"10\">" + "</textarea></td></tr>"
		
	} else {
		html = html + "<tr><td>LINK:</td><td><input type=\"text\" class=\"form-control\" id=\"LINK\" name=\"LINK\" value=\"" + vals + "\"></td></tr>"	
	};
	$("#tedit").html(html)
	if(id!=''){
			$.post("/custom",{ID:id,CMD:'HTML',_xsrf:xsrf},function(data){$("#EHTML").html(data)});
			$("#CMD").val('UP');
			$("#ID").val(id);
			} else {$("#CMD").val('NEW')}
	$("#Cedit").modal()
}
$("#DUOSHUO").click(function(){
	var msg="确定要设置多说ID？\n注意：设置错误的多说ID将会导致留言板功能不可用！";
	if (confirm(msg)){
	$.post("/custom",{_xsrf:xsrf,CMD:'DUOSHUO',name:$("#DS").val()},function(data){alert(data)})
}});

$("#jsupdate").click(function(data){
	$.post("/custom",{CMD:'JS',TYPE:'UP',EHTML:$("#JS").val(),_xsrf:xsrf},function(data){alert(data);location.reload();});
})
</script>
{% end %}